
package fr.umlv.m2.jee.portailEtudiant.web.admin.Action.Formation;

import com.opensymphony.xwork2.ActionSupport;
import fr.umlv.m2.jee.portailEtudiant.service.DisplayCourse;
import fr.umlv.m2.jee.portailEtudiant.service.DisplayFormation;
import fr.umlv.m2.jee.portailEtudiant.service.IDisplayFormationService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: soufianeelghariaoui
 * Date: 18/04/11
 * Time: 22:59
 * To change this template use File | Settings | File Templates.
 */
public class Formation extends ActionSupport {

    @Autowired
    private IDisplayFormationService formationService;
    private String name;
    private List<DisplayFormation> displayFormation;
    private List<DisplayCourse> displayCourse;
    private DisplayFormation dispFormation;
    private String id;
    private String nameCourse;
    private String idCourse;


    @Override
	public String execute() throws Exception {
        System.out.println("ds execute 1");
		displayFormation = formationService.getAllDisplayFormation();
        System.out.println("ds execute 2");
		return SUCCESS;

	}



	public String showCourse() throws Exception {
        System.out.println("ds execute 1");
        System.out.println(getName());
		displayCourse = formationService.getAllCourseById(getName());
        dispFormation = formationService.getFormationByName(getName());
        System.out.println("ds execute 2");
		return SUCCESS;

	}

    public String deleteFormation() throws Exception {

        System.out.println("ds execute 1delete ");
        formationService.removeFormation(getName());
        System.out.println("ds execute 2 delete");
		displayFormation = formationService.getAllDisplayFormation();
        System.out.println("ds execute 2");
		return SUCCESS;
    }

    public String editDispFormation() throws Exception {
        System.out.println("ds execute 1 update ");
        System.out.println(getName());
        dispFormation = formationService.getFormationByName(getName());
        System.out.println("ds execute 2 update ");
        return SUCCESS;
    }

    public String editFormation() throws Exception {
        System.out.println("ds execute 1 edit ");
        System.out.println("****************"+getId());
        System.out.println("***********¨****"+getName());
        if( getId()!= "") {
            System.out.println(getId());
            System.out.println(getName());
            System.out.println("ds execute 2 edit ");

            dispFormation = formationService.getFormationById(Long.parseLong(id));
            dispFormation.setName(getName());
            formationService.update(dispFormation);

             displayFormation = formationService.getAllDisplayFormation();

            return SUCCESS;
        } else {
            return INPUT;
        }

    }

    public String addFormation() throws Exception {
        System.out.println("***********¨**** addFormation "+getName());
        formationService.addFormation(getName());
        displayFormation = formationService.getAllDisplayFormation();
        return SUCCESS;
    }

    public String addCourse() throws Exception {
       System.out.println("ds execute 1  add course ");
       System.out.println("***********¨**** nom Formation add course " +getName());
        //formationService.addCourse(Long.parseLong(id),getName(),getNameCourse());
        //displayCourse = formationService.getAllCourseById(getName());
        dispFormation =formationService.getFormationByName(getName());
        System.out.println("ds execute 2  add course ");
        return SUCCESS;
    }

    public String addCourseToFormation() throws Exception {
        System.out.println("ds execute 1  add course to formation ");
        System.out.println("***********¨**** nom Formation " +getName());
        System.out.println("***********¨**** nom cour " +getNameCourse());
        formationService.addCourse(getName(),getNameCourse());
        displayCourse = formationService.getAllCourseById(getName());
        System.out.println("ds execute 2  add course to formation ");
        return SUCCESS;
    }

    public String editCourse() throws Exception {

        System.out.println("ds execute 1  edit course to formation ");
        System.out.println("***********¨**** nom Formation " +getName());
        System.out.println("***********¨**** nom cour " +getNameCourse());
        dispFormation = formationService.getFormationByName(getName());


        return SUCCESS;
    }

    public String SaveEditCourse() throws Exception {
        System.out.println("ds execute 1  edit 2 course to formation ");
        System.out.println("***********¨**** nom Formation " +getName());
        System.out.println("***********¨**** nom cour " +getNameCourse());

      //  dispFormation = formationService.getFormationById(Long.parseLong(id));
       // dispFormation.getCourse().setName(getName());
       // formationService.update(dispFormation);

             //      displayFormation = formationService.getAllDisplayFormation();
        return SUCCESS;

    }






    public void setFormationService(IDisplayFormationService formationService) {
        this.formationService = formationService;
    }

    public List<DisplayFormation> getDisplayFormation() {
        return displayFormation;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public List<DisplayCourse> getDisplayCourse() {
        return displayCourse;
    }

    public DisplayFormation getDispFormation() {
        return dispFormation;
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getNameCourse() {
        return nameCourse;
    }

    public void setNameCourse(String nameCourse) {
        this.nameCourse = nameCourse;
    }

    public String getIdCourse() {
        return idCourse;
    }
}
